package com.lzit.smart_canteen.repository;

import com.lzit.smart_canteen.domain.Food;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface FoodRepository extends JpaRepository<Food,Integer> {
    @Query(value = "SELECT win FROM t_food f GROUP BY win",nativeQuery = true)
    List<Integer> findWindow();

    List<Food> findFoodsByWindow(Integer window);

    Food findFoodById(Integer id);

    @Transactional
    @Modifying
    @Query(value = "UPDATE t_food SET status=?2 WHERE id=?1", nativeQuery = true)
    void updateStatusById(Integer id, String status);
}
